package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.service.RegisterService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@Controller
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping("register")
    @ResponseBody
    public ServerResponse add(Customer customer, HttpSession session){
        ServerResponse serverResponse1 = registerService.add(customer);
        if(serverResponse1.getCode()==200) {
            ServerResponse serverResponse = registerService.getCustTel(customer.getCustTel(), customer.getCustPassword());
            session.setAttribute("serverResponse", serverResponse);
        }
        return ServerResponse.getSuccess("注册成功");
    }

//    @PostMapping("register")
//    @ResponseBody
//    public  String regist(Long custTel, String custPassword){
//        System.out.println("custTel:" + custTel);
//        System.out.println("password:" + custPassword);
//
//
//        System.out.println("从页面中获得的密码是：" +custPassword );
//        registerService.regist(custTel,custPassword);
//        return "success";
//    }

}
